package com.study.spring_ai.tool;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.ai.tool.definition.ToolDefinition;
import org.springframework.ai.tool.method.MethodToolCallback;
import org.springframework.ai.util.json.schema.JsonSchemaGenerator;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Method;

/**
 * @author dejavu
 * @since 2025/7/21
 */
public class MethodTools {

    public static void main(String[] args) {
        Method method =  ReflectionUtils.findMethod(DateTimeTools.class, "getCurrentDateTime");
        ToolCallback toolCallback = MethodToolCallback.builder()
                .toolDefinition(ToolDefinition.builder()
                        .name("getCurrentDateTime")
                        .description("Get the current date and time in the user's timezone")
                        .inputSchema(JsonSchemaGenerator.generateForMethodInput(method))
                        .build())
                .toolMethod(method)
                .toolObject(new DateTimeTools())
                .build();
        ChatClient.builder(OllamaChatModel.builder().ollamaApi(OllamaApi.builder().build()).build())
                .defaultTools(toolCallback);
    }
}
